<template>
  <el-dialog show-close width="50%"
             title="密码重置"
             v-model="dialogVisible"
             :before-close="handleClose"
             append-to-body>
    <start-update-user-pwd v-if="dialogVisible" ref="startUpdateUserPwd" :user-id="userId"
                           :show-old-pwd="showOldPwd">

    </start-update-user-pwd>
    <div slot="footer" class="text-right">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="submitData">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {View} from "@element-plus/icons-vue";
import StartUpdateUserPwd from "components/start-components/startDpdateUserPwd/index.vue";

export default {
  name: "startUpdateUserPwdDialog",
  components: {StartUpdateUserPwd, View},
  props: {
    showOldPwd: {
      type: Boolean,
      default: false,
    },
    successMsg: {
      type: String,
      default: "密码重置成功",
    },
    updatePwdApi: {
      type: Function,
      required: true,
    },
  },

  data() {
    return {
      dialogVisible: false,
      userId: null,
    }
  },
  methods: {
    show(userId) {
      this.userId = userId;
      this.dialogVisible = true
    },
    handleClose() {
      this.dialogVisible = false
      this.userId = null
    },

    submitData() {
      this.$refs.startUpdateUserPwd.submitData().then((res) => {
        return this.updatePwdApi(res)
      }).then(res => {
        if (this.successMsg || this.successMsg.length > 0) {
          this.$message.success(this.successMsg)
        }
        this.handleClose();
      })

    }
  }
}
</script>

<style scoped>

</style>
